#ifndef _CRT_SECURE_NO_WARNINGS
	#define _CRT_SECURE_NO_WARNINGS // Deal with warnings in glui.h
#endif

#include <GL\glui.h>
#include "Cameras.h"
#include "Animation.h"
#include "Objects.h"

int current_camera_index = CAMERA1_INDEX;

Camera cams[] = { {CAMERA1_INDEX, setCam1, "Cam 1"},
				  {CAMERA2_INDEX, setCam2, "Cam 2"},
				  {CAMERA3_INDEX, setCam3, "Cam 3"}
				};

GLdouble cam2[3][3] = {
	{ 0.0, 150, 0.0},
	{ 0.0, 0.0, 0.0},
	{-1.0, 0.0, 0.0}
};

GLdouble cam3[3][3] = {
	{ROBOT_X_CENTER - ROBOT_DIM_X, ROBOT_Y_CENTER + ROBOT_DIM_Y * 5, ROBOT_Z_CENTER},
	{ROBOT_X + robot_posx, ROBOT_Y, ROBOT_Z + robot_posz},
	{0.0, 1.0, 0.0}
};

float obj_pos[] = { 0.0, 0.0, 0.0 };
float view_rotate[16] = { 1,0,0,0,
                          0,1,0,0,
                          0,0,1,0,
                          0,0,0,1 };

void setCam1() {    
	glTranslatef( obj_pos[0], obj_pos[1], -obj_pos[2]-50 );
	glRotated( 20.0, 1.0,0.0,0.0 );
	glRotated(-10.0, 0.0,1.0,0.0 );
	glMultMatrixf( view_rotate );
}

void setCam2() {
	gluLookAt(cam2[CAM_EYE_INDEX][0],	 cam2[CAM_EYE_INDEX][1],	cam2[CAM_EYE_INDEX][2], 
			  cam2[CAM_CENTER_INDEX][0], cam2[CAM_CENTER_INDEX][1], cam2[CAM_CENTER_INDEX][2],
			  cam2[CAM_UP_INDEX][0],	 cam2[CAM_UP_INDEX][1],		cam2[CAM_UP_INDEX][2]
	);
}

void setCam3() {
	gluLookAt(cam3[CAM_EYE_INDEX][0],	 cam3[CAM_EYE_INDEX][1],	cam3[CAM_EYE_INDEX][2], 
			  ROBOT_X + robot_posx,		 ROBOT_Y,					ROBOT_Z + robot_posz,
			  cam3[CAM_UP_INDEX][0],	 cam3[CAM_UP_INDEX][1],		cam3[CAM_UP_INDEX][2]
	);
}

void showCamId(char *cam_id) {
	int length = strlen(cam_id);
	
	// Sets Projection and Modelview matrices for 2D Rendering
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
		glLoadIdentity();
		gluOrtho2D(0.0, 100.0, 0.0, 100.0);

		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
			glLoadIdentity();

			glDisable(GL_LIGHTING);
			glColor3f(1.0, 1.0, 1.0);
			glRasterPos2f(1.0, 100.0 - 5.0);
			for(int i = 0; i < length; ++i) {
				glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, cam_id[i]);
			}
			
			glEnable(GL_LIGHTING);
			glMatrixMode(GL_MODELVIEW); // Resets the Matrices for 3D Rendering
		glPopMatrix();
		glMatrixMode(GL_PROJECTION);
	glPopMatrix();

}